<template>
  <div class="container">
    <div class="head__row flex-3">
      <span class="title">申请项目详情</span>
      <span class="title__sub">{{type != 0 ? '已审核' : '待审核' }}</span>
    </div>
    <table class="table__detail">
      <tbody>
        <tr class="tr__1">
          <td class="column__key">项目名称</td>
          <td class="column__value" colspan="2">{{item.name}}</td>
          <td class="column__key">申请时间</td>
          <td class="column__value" colspan="2">{{formatDay(item.publishTime)}}</td>
        </tr>
        <tr class="tr__1">
          <td class="column__key">申请人</td>
          <td class="column__value">{{item.operaterName + "(" + item.userRealName + ")"}}</td>
          <td class="column__key">联系方式</td>
          <td class="column__value">{{item.mobilephone}}</td>
          <td class="column__key">已有项目数</td>
          <td class="column__value">-</td>
        </tr>
        <tr class="tr__1">
          <td class="column__key">合买类型</td>
          <td class="column__value">{{item.type}}</td>
          <td class="column__key">保底收益</td>
          <td class="column__value">{{item.yeild}}%</td>
          <td class="column__key">股侠分成</td>
          <td class="column__value">{{item.shareRate}}%</td>
        </tr>
        <tr class="tr__1">
          <td class="column__key">项目周期</td>
          <td class="column__value">T + {{item.timeLimit}}</td>
          <td class="column__key">止盈率</td>
          <td class="column__value">{{item.terminateRate}}%</td>
          <td class="column__key">领投金额</td>
          <td class="column__value">{{item.operateInvestAmount}}</td>
        </tr>
        <tr class="tr__1">
          <td class="column__key">项目杠杆</td>
          <td class="column__value">1:{{item.leverageRate}}</td>
          <td class="column__key">项目总额</td>
          <td class="column__value">{{item.raiseAmount}}</td>
          <td class="column__key">清仓线</td>
          <td class="column__value">{{item.clearanceRate}}%</td>
        </tr>
        <tr class="tr__1">
          <td class="column__key">股侠宣言</td>
          <td class="column__value" colspan="5">{{item.declaration}}</td>
        </tr>
        <tr class="tr__2" v-if="item.userType == 0">
          <td class="column__key">股侠简介</td>
          <td class="column__value" colspan="5">{{item.operatorDescription}}</td>
        </tr>
      </tbody>
    </table>
    <div class="commit__box">
      <div class="commit__title">审核员意见</div>
      <textarea v-model="commit" :readonly="type != 0" placeholder="请填写对该项目和申请人的意见，选填" maxlength="300"></textarea>
    </div>
    <div class="btn__box" >
      <div class="btn__default btn__margin" v-if="type == 0" @click="pass">通过</div>
      <div class="btn__default btn__margin" v-if="type == 0" @click="refuse">拒绝</div>
      <div class="btn__default btn__margin" v-if="type != 0" @click="goBack">返回</div>
    </div>
    <AModal :status.sync="passStatus" content="该用户是第一次申请项目，确认通过吗？" @confirm="passProject"/>
    <AModal :status.sync="refuseStatus" content="确认拒绝该项目吗？" @confirm="refuseProject"/>
  </div>
</template>

<script>
import {ATable, AModal} from '@/components';
import Api from '@/api';
import dayjs from 'dayjs';
import { Message } from 'iview';
export default {
  name: 'auditdetail',
  components: {
    ATable,
    AModal,
  },
  props: {
    type: {
      required: true,
      type: [String, Number]
    },
    id: {
      required: true,
      type: [String, Number]
    },
    // params: {
    //   required: true,
    //   type: Object,
    // }
  },
  data() {
    return {
      item: {

      },
      commit: '',
      passStatus: false,
      refuseStatus: false,
    }
  },
  created() {
    // this.item = JSON.parse(localStorage.getItem('audit'));
    this.getProjectDetail();
    this.commit = this.item.auditOpinion;
  },
  methods: {
    pass() {
      if(this.item.userType != 0) {
        this.passProject();
      } else {
        this.passStatus = true;
      }
    },
    refuse() { 
      this.refuseStatus = true;
    },
    getProjectDetail() {
      Api.getAuditDetail({params: {projectId: this.id}}).then(res => {
        console.log(res);
        this.item = res.data;
      }).catch(err => {
        this.goBack();
      });
    },
    passProject() {
      Api.operateProject({
        projectId: this.id,
        passed: 'Y',
        auditOpinion: this.commit,
      }).then(res => {
        Message.success({content: res.message});
        this.goBack();
        console.log('通过');
        this.passStatus = false;
      });
    },
    refuseProject() {
      Api.operateProject({
        projectId: this.id,
        passed: 'N',
        auditOpinion: this.commit,
      }).then(res => {
        Message.success({content: res.message});
        this.goBack();
        console.log('决绝');
        this.refuseStatus = false;
      });
    },
    goBack() {
      this.$router.go(-1);
      console.log('返回');
    },
    formatDay(time) {
      return dayjs(time).format('YYYY-MM-DD HH:mm')
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '../styles/auditdetail.styl';
</style>
